home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’94
/
[√] Distribution Restricted!
/
Steve Sisak
/
TMFutures
/
UFailure.h
< prev
Wrap
Text File
|
1994-06-26
|
4KB
|
138 lines
// UFailure.h
// Copyright © 1984-1993 by Apple Computer Inc. All rights reserved.
#ifndef __UFAILURE__
#define __UFAILURE__
#ifndef __SETJMP__
#include <setjmp.h>
#endif
#ifndef __TYPES__
#include <Types.h>
#endif
#if qDebug
#include <string.h>
#endif
#define qDebug 1
//----------------------------------------------------------------------------------------
// This macro can be called on any variable to keep it out of a register. It is
// used specifically in exception handling. Kludge to be used till volatile or
// C++ exception handling is implemented.
//----------------------------------------------------------------------------------------
#define VOLATILE(a) ((void) &a)
//----------------------------------------------------------------------------------------
// Max and min error number constants
//----------------------------------------------------------------------------------------
#define minErr (-32768)
#define maxErr (32767)
//----------------------------------------------------------------------------------------
// FailInfo
//----------------------------------------------------------------------------------------
typedef struct FailInfo FailInfo, *FailInfoPtr;
struct FailInfo {
jmp_buf savedState;
OSErr error;
long message;
FailInfo* nextInfo;
#if qDebug
short installed;
#endif
};
//----------------------------------------------------------------------------------------
// Global macro definitions
//----------------------------------------------------------------------------------------
// The Try macro has taken the place of the FailInfo::Try method, for the
// reason that the code has to _always_ be inline. The decision as to
// whether or not code is inlined is implemented very differently for various
// compilers, and can be affected by options such as symbolics generation and
// level of optimization. Because this decision is so far out of our control,
// the only real guarantee is to implement Try as a macro…
//
// The old way:
//
// FailInfo fi;
// if (fi.Try())
// {
// …
//
// The new way:
// FailInfo fi;
// Try(fi)
// {
// …
//
#define Try(f) \
f.nextInfo = gTopHandler; \
f.error = noErr; \
f.message = 0; \
f.installed = 1; \
gTopHandler = &f; \
if (setjmp(f.savedState) == 0)
//----------------------------------------------------------------------------------------
// Global variable declarations
//----------------------------------------------------------------------------------------
extern FailInfoPtr gTopHandler;
//----------------------------------------------------------------------------------------
// Global function declarations
//----------------------------------------------------------------------------------------
void Assertion(const Boolean condition, const StringPtr description);
#define BuildMessage(lowWord, highWord) (((long)highWord << 16) | (lowWord & 0xFFFF))
void Failure(OSErr error, long message);
void FailMemError();
void FailResError();
void FailNewMessage(OSErr error, long oldMessage, long newMessage);
void FailNIL(void* p);
void FailNILResource(Handle r);
void FailOSErr(OSErr error);
Boolean ErrorIs(OSErr expectedError, OSErr error);
Boolean HandlerExists(FailInfoPtr testFailInfoPtr);
void Success(FailInfo* fi);
void ProgramBreak(const StringPtr grievance);
void ProgramReport(const StringPtr grievance, const Boolean breakInDebugger);
#define ReSignal(fi) Failure((fi)->error, (fi)->message)
//----------------------------------------------------------------------------------------
// FailInfo inline method definitions
//----------------------------------------------------------------------------------------
#endif